<html>
<head><meta charset="utf-8"><title>Add a scheme to register functions from o… compiler-team#395 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html">Add a scheme to register functions from o… compiler-team#395</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221244385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221244385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221244385">(Dec 30 2020 at 20:35)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/395">Add a scheme to register functions from other crates with TyCtxt #395</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="221244488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221244488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221244488">(Dec 30 2020 at 20:36)</a>:</h4>
<p>could we use this for shrinking rustc_middle even more? :)</p>



<a name="221244837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221244837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221244837">(Dec 30 2020 at 20:41)</a>:</h4>
<p>Could we generalize the query subsystem to have queries that do not cache results and thus have lower overhead and don't require stablehash?</p>



<a name="221245010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245010">(Dec 30 2020 at 20:44)</a>:</h4>
<p>I think we already have a bunch of attributes on queries in that direction. I was mostly hoping for avoiding the query infrastructure entirely and just have a function pointer and a wrapper function that calls the pointer</p>



<a name="221245027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245027">(Dec 30 2020 at 20:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395/near/221244488">said</a>:</p>
<blockquote>
<p>could we use this for shrinking rustc_middle even more? <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
</blockquote>
<p>I'm hoping for this to be a welcome side effect of such a system, yes</p>



<a name="221245032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245032">(Dec 30 2020 at 20:44)</a>:</h4>
<p>I think the rust language in general could benefit from 'header files' where you can declare the function separately from implementing it</p>



<a name="221245036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245036">(Dec 30 2020 at 20:44)</a>:</h4>
<p>I guess that's traits?</p>



<a name="221245057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245057">(Dec 30 2020 at 20:44)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> what's the difference between your idea and an extension trait?</p>



<a name="221245093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245093">(Dec 30 2020 at 20:45)</a>:</h4>
<p>well... in my scheme, you can invoke the function on <code>TyCtxt</code> in <code>rustc_middle</code> and define the function in <code>rustc_mir</code></p>



<a name="221245096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245096">(Dec 30 2020 at 20:45)</a>:</h4>
<p>an extension trait must be either defined in the extern crate, in which case it can't be used in <code>rustc_middle</code></p>



<a name="221245152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245152">(Dec 30 2020 at 20:46)</a>:</h4>
<p>or defined in <code>rustc_middle</code> to use it, in which case you can't externally implement it for <code>TyCtxt</code></p>



<a name="221245165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245165">(Dec 30 2020 at 20:46)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="492">@T-compiler</span>: Proposal <a href="https://github.com/rust-lang/compiler-team/issues/395#issuecomment-752753218">#395</a> has been seconded, and will be approved in 10 days if no objections are raised.</p>



<a name="221245197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245197">(Dec 30 2020 at 20:47)</a>:</h4>
<p>Hmm, that makes sense</p>



<a name="221245201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245201">(Dec 30 2020 at 20:47)</a>:</h4>
<p>rust could benefit from "header files" or well, we could instead use extern functions</p>



<a name="221245209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245209">(Dec 30 2020 at 20:47)</a>:</h4>
<p>and use <code>#[no_mangle]</code></p>



<a name="221245215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245215">(Dec 30 2020 at 20:47)</a>:</h4>
<p>but that seems worse to me</p>



<a name="221245220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245220">(Dec 30 2020 at 20:47)</a>:</h4>
<p>This sort of sounds like #[global_allocator] where there should only be one implementation but you don't care where it is</p>



<a name="221245233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245233">(Dec 30 2020 at 20:47)</a>:</h4>
<p>which is pretty much how header files work</p>



<a name="221245312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245312">(Dec 30 2020 at 20:48)</a>:</h4>
<p>Yea, I'm looking for something that doesn't give linker errors ^^</p>



<a name="221245313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245313">(Dec 30 2020 at 20:49)</a>:</h4>
<p>c is a nice language because it hides it's ugliness</p>



<a name="221245330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221245330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221245330">(Dec 30 2020 at 20:49)</a>:</h4>
<p>I think starting with traits or so is right, and if it gets too painful or performance cost is too high we can replace it with linker and compiler magic.</p>



<a name="221255709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221255709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221255709">(Dec 30 2020 at 23:32)</a>:</h4>
<p>In my opinion, rustc_middle now essentially contains datatype definitions and the query system. Without the query system, it is essentially of the same size at rustc_typeck. This kind of forward declarations can make the call graph even more complex than it is now.</p>



<a name="221287854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221287854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221287854">(Dec 31 2020 at 12:47)</a>:</h4>
<p>I think my only concern here is debuggability -- already with queries, it can be quite hard to figure out "which code is executed by this function call". Grepping for "the query implementation" is non-trivial. It would be good to consider this.</p>



<a name="221287877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/221287877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#221287877">(Dec 31 2020 at 12:47)</a>:</h4>
<p>E.g., there could be some macro that is used for this such that one has some "key" to grep for.</p>



<a name="222716419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Add%20a%20scheme%20to%20register%20functions%20from%20o%E2%80%A6%20compiler-team%23395/near/222716419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Add.20a.20scheme.20to.20register.20functions.20from.20o.E2.80.A6.20compiler-team.23395.html#222716419">(Jan 14 2021 at 13:29)</a>:</h4>
<p>This proposal has been accepted: <a href="https://github.com/rust-lang/compiler-team/issues/395">#395</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>